package com.neuedu.yyzxproject.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neuedu.yyzxproject.mapper.NurseContentMapper;
import com.neuedu.yyzxproject.pojo.Nursecontent;
import com.neuedu.yyzxproject.service.NurseContentService;
import com.neuedu.yyzxproject.vo.PageInfoVo;
import com.neuedu.yyzxproject.vo.PageResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NurseContentServiceImpl implements NurseContentService {
    @Autowired
    private NurseContentMapper nurseContentMapper;

    private <T> PageResponseVo<T> getPageResponse(List<T> list) {
        PageInfo<T> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal();
        int pageSize = pageInfo.getPageSize();
        int currentPage = pageInfo.getPageNum();
        int pages = pageInfo.getPages();
        List<T> dataList = pageInfo.getList();

        PageResponseVo<T> pageResponseVo = new PageResponseVo<>();
        pageResponseVo.setData(dataList);
        pageResponseVo.setCurrentPage(currentPage);
        pageResponseVo.setPageSize(pageSize);
        pageResponseVo.setTotal(total);
        pageResponseVo.setPageNum(pages);
        return pageResponseVo;
    }

    @Override
    public PageResponseVo<Nursecontent> queryAllNurseContentInfo(PageInfoVo pageInfoVo, Nursecontent nursecontent) {
        PageHelper.startPage(pageInfoVo.getCurrentPage(), pageInfoVo.getPageSize());
        List<Nursecontent> nursecontents = nurseContentMapper.queryAllNurseContentInfo(nursecontent);
        return getPageResponse(nursecontents);
    }

    @Override
    public int addNurseContent(Nursecontent nursecontent) {
        return nurseContentMapper.addNurseContent(nursecontent);
    }

    @Override
    public int updateNurseContent(Nursecontent nursecontent) {
        return nurseContentMapper.updateNurseContent(nursecontent);
    }

    @Override
    public int deleteNurseContent(Nursecontent nursecontent) {
        return nurseContentMapper.deleteNurseContent(nursecontent);
    }

}
